package worldinruin.gui.imp.gameview.gameboard.tiles;

import java.awt.GridLayout;

import javax.swing.JPanel;

import worldinruin.core.IMap;

public class MapPanel extends JPanel {
	
	private TileViewFactory tileViewFactory = new TileViewFactory();
	private TileView[][] tileViews;
	
	/**
	 * Creates a map panel which is a container for maps.
	 * @param map Map to put in container.
	 */
	public MapPanel(IMap map){
		tileViews = new TileView[map.getNumberOfRows()][map.getNumberOfColumns()];
		loadMap(map);		
	}
	
	/**
	 * Loads a map into the container.
	 * @param map
	 */
	public void loadMap(IMap map){		
		removeAll();
		
		setLayout(new GridLayout(map.getNumberOfRows(), map.getNumberOfColumns()));
		
		for (int r = 0; r < map.getNumberOfRows(); r++){			
			for (int c = 0; c < map.getNumberOfColumns(); c++){				
				tileViews[r][c] = tileViewFactory.newTile(map.getTile(r, c));  
				add(tileViews[r][c]);
			}
			
		}
		
	}
}
